require "Common/define"


SpineEffectParam = {};
SpineEffectParam.__index = SpineEffectParam;

local cacheList = {}

function SpineEffectParam.Get(effectRes, depth, flip, actionName,skillId)
    local obj = table.remove(cacheList, 1);
    if obj then
        obj.skillId = skillId;
        obj.effectRes = effectRes;
        obj.actionName = actionName;

        obj.depth = depth or 0;

        obj.pos = Vector3.zero;
        obj.offset = {0, 0};
        obj.duration = nil;

        obj.flip = flip or false;
        obj.speed = nil;
        obj.loop = false;

        obj.follow = false;
        obj.followInfo = nil;
        obj.followTrans = nil;
        obj.followBone = nil;
        obj.followBoneSpineTrans = nil;

        obj.linkEffect = false;
        obj.followInfo1 = nil;

        obj.flyHold = false;

        obj.delay = 0;
        obj.fighterId = 0;
        obj.scale = 1;
        obj.timeScale = 1;
        obj.hook = false;
        obj.caster = nil;
        obj.suffer = nil;
        obj.f_AxisDeviation=0;
        obj.spineType = 0;
        obj.targetPos = nil;
        return obj;
    end
    return SpineEffectParam:new(effectRes, depth, flip, actionName,skillId)
end

function SpineEffectParam.Put(obj)
    if not obj then
        return
    end
    obj.skillId = 0
    obj.effectRes = nil
    obj.actionName = nil

    obj.depth = nil --0

    --obj.pos = Vector3.zero
    --obj.offset = {0, 0}
    obj.duration = nil-- -1

    obj.flip = false
    --obj.speed = nil--Vector3(1 0 0)
    obj.loop = false

    obj.follow = false
    obj.followInfo = nil
    obj.followTrans = nil
    obj.followBone = nil
    obj.followBoneSpineTrans = nil

    obj.linkEffect = false
    obj.followInfo1 = nil

    obj.flyHold = false

    obj.delay = 0
    obj.fighterId = 0
    obj.scale = 1
    obj.timeScale = 1
    obj.hook = false
    obj.caster = nil
    obj.suffer = nil
    obj.f_AxisDeviation=0
    obj.spineType = 0;
    obj.targetPos = nil;
    table.insert(cacheList, obj)
end

--effectRes, actionName, depth, pos, offset, duration, flip, speed,loop,follow,parent,flyHold, castTrans,delay, isShadow, buffServerId
--16个参数，已经挺多的了
function SpineEffectParam:new(effectRes, depth, flip, actionName,skillId)
    local object = {
        skillId = skillId,
        effectRes = effectRes,
        actionName = actionName,

        depth = depth or 0, --0,

        pos = Vector3.zero,
        offset = {0, 0},
        duration = nil,-- -1

        flip = flip or false,
        speed = nil,--Vector3(1, 0, 0)
        loop = false,

        follow = false,
        followInfo = nil,
        followTrans = nil,
        followBone = nil,
        followBoneSpineTrans = nil,

        linkEffect = false,
        followInfo1 = nil,

        flyHold = false,

        delay = 0,
        fighterId = 0,
        scale = 1,
        timeScale = 1,
        hook = false,
        caster = nil,
        suffer = nil,
        f_AxisDeviation=0,
        spineType = 0;
    };

    setmetatable(object, SpineEffectParam);
    return object;
end
function SpineEffectParam:setSpineType(spineType)
    self.spineType = spineType;
end
function SpineEffectParam:setPosition(position)
    self.pos = position;
end
---@param 设置施法者，有些特效需要知道施法者状态，比如连线
function SpineEffectParam:setCaster(entity)
    self.caster = entity
end
---@param 设置接受者，有些特效需要知道状态，比如连线
function SpineEffectParam:setSuffer(entity)
    self.suffer = entity
end
---@param 设置渲染层级
function SpineEffectParam:setRenderDeepZ(f_AxisDeviation)
    self.f_AxisDeviation = f_AxisDeviation
end
--function SpineEffectParam:setFollow(followTrans, offset)
--    self.follow = true;
--    self.parent = followTrans;
--
--    self.offset = offset;
--end

function SpineEffectParam:setFollow(followTrans, offset, followBone, followBoneSpineTrans)
    self.follow = true;

    --self.followTrans = followTrans;
    --self.offset = offset;
    --self.followBone = followBone;
    --self.followBoneSpineTrans = followBoneSpineTrans;

    self.followInfo = {};
    self.followInfo.followTrans = followTrans;
    self.followInfo.offset = offset;
    self.followInfo.followBone = followBone;
    self.followInfo.followBoneSpineTrans = followBoneSpineTrans;

end

--在setFollow后面调用
function SpineEffectParam:setLinkFollow(followTrans, offset, followBone, followBoneSpineTrans)
    self.follow = false;
    self.linkEffect = true;

    --self.followTrans = followTrans;
    --self.offset = offset;
    --self.followBone = followBone;
    --self.followBoneSpineTrans = followBoneSpineTrans;

    self.followInfo1 = {};
    self.followInfo1.followTrans = followTrans;
    self.followInfo1.offset = offset;
    self.followInfo1.followBone = followBone;
    self.followInfo1.followBoneSpineTrans = followBoneSpineTrans;

end
--在setFollow后面调用
function SpineEffectParam:setHookFollow(followTrans, offset, followBone, followBoneSpineTrans)
    self.follow = false;
    self.hook = true;

    --self.followTrans = followTrans;
    --self.offset = offset;
    --self.followBone = followBone;
    --self.followBoneSpineTrans = followBoneSpineTrans;

    self.followInfo1 = {};
    self.followInfo1.followTrans = followTrans;
    self.followInfo1.offset = offset;
    self.followInfo1.followBone = followBone;
    self.followInfo1.followBoneSpineTrans = followBoneSpineTrans;

end
--duration为负时，是技能做循环表现，为了和buff区分开
function SpineEffectParam:setDuration(duration)
    self.duration = duration;
end

function SpineEffectParam:setFly(position, speed, flyHold)
    self.pos = position;
    self.speed = speed;
    self.flyHold = flyHold;
end
function SpineEffectParam:setSpeed(speed)
    self.speed = speed;
end

--function SpineEffectParam:setBuffServerId(buffServerId)
--    self.buffServerId = buffServerId;
--end

function SpineEffectParam:setDelay(delay)
    self.delay = delay;
end

--function SpineEffectParam:setShadow(isShadow)
--    self.isShadow = isShadow;
--end

function SpineEffectParam:setLoop(loop)
    self.loop = loop;

    if self.loop then
        self.duration = nil;
    end
end

function SpineEffectParam:setFighterId(fighterId)
    self.fighterId = fighterId or 0;
end

function SpineEffectParam:setTimeScale(timeScale)
    self.timeScale = timeScale or 1;
end
function SpineEffectParam:setFlip(flip)
    self.flip = flip;
end
function SpineEffectParam:setTargetPos(targetPos)
    self.targetPos = Vector3.New(targetPos.x,300,targetPos.y);
end
